<template>
  <div class="navbar">
    <span class="collapse" @click="handleCollapse">
      <i class="el-icon-s-fold"></i
    ></span>
    <!-- 用户中心 -->
    <div class="user-info">
      <i class="el-icon-date" @click="showDate"></i>
      <i class="el-icon-chat-line-square"></i>
      <i class="el-icon-full-screen" @click="handleFullScreen"></i>
      <!-- 下拉菜单 -->
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{ userName }} <i class="el-icon-arrow-down"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="info">
            <i class="el-icon-user"></i> 个人中心</el-dropdown-item
          >
          <el-dropdown-item command="password">
            <i class="el-icon-edit-outline"></i>修改密码</el-dropdown-item
          >
          <el-dropdown-item command="logout">
            <i class="el-icon-s-unfold"></i>退出登录</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <!-- 日历弹出框 -->
    <el-dialog
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-calendar v-model="calendar"> </el-calendar>
    </el-dialog>
  </div>
</template>
<script>
// 全屏组件
import screenfull from 'screenfull'
export default {
  name: 'NavBar',
  data () {
    return {
      dialogVisible: false,
      calendar: new Date(),
      userName: 'admin'
    }
  },
  mounted () {
    this.getUserName()
  },
  methods: {
    getUserName () {

    },
    // 展示日历
    showDate () {
      console.log('11111')
      this.dialogVisible = true
    },
    // 关闭日历弹出框
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    handleCollapse () {
      this.$emit('handleCollapse') // 发送事件
    },
    handleFullScreen () {
      // 全屏
      screenfull.toggle()
    },
    handleCommand (type) {
      console.log(type)
      if (type === 'logout') {
        this.$confirm('确定要退出嘛？', '退出提示')
          .then(() => {
            window.localStorage.removeItem('userInfo')
            window.localStorage.removeItem('token')
            this.$router.push('/login')
          })
          .catch(() => {})
      }
    }
  }
}
</script>
<style scoped>
.navbar {
  height: 60px;
  width: 100%;
  background-color: #03a0d4;
  line-height: 60px;
  padding: 0px;
  display: flex;
}
.collapse {
  cursor: pointer;
  padding: 0 20px;
  color: #ffffff;
}
.user-info {
  height: 60px;
  width: 400px;
  margin-left: auto;
  padding-right: 20px;
  text-align: right;
}
.user-info > i {
  cursor: pointer;
  padding: 10px 15px;
  color: #ffffff;
}
.el-dropdown {
  margin-left: 10px;
}
.el-dropdown-link {
  color: #ffffff;
  cursor: pointer;
}
.el-dropdown-menu .el-dropdown-item {
  padding: 0 10px;
}
</style>
